<?php 
	include "restritoCliente.php";
	if (!isset($_SESSION)){
		session_start();
	}
	header("Content-Type: text/html; charset=UTF-8", true);
?>

<?php 

include_once 'BudgetControl.php';
include_once 'Budget.php';

if (!isset($_SESSION)){
	session_start();
}

$pedido = BudgetControl::getDetailsBudget($idPedido);


?>

<form class="join-form" name="detalhesPedido"  enctype="multipart/form-data" method="POST" action="">
		<span class="highlights">Pedido Nº <strong><?php echo $pedido->BudgetId;?></strong></span>
        
		<table class="table_pedido">
			<tr class="row" id="table-categories">
            	
				<th class="categories">Descrição</th>
				<th class="categories">Foto</th>
				<th class="categories">Quant</th>
				<th class="categories">Preço Unitário</th>
				
				
		  </tr>
		  
		  <?php 
		  
		  $total = 0;
		  foreach ($pedido->Products as $product)
		  {
		  	echo '<tr class="row">';
		  	
		  	echo '<td class="table-column description"><span class="product-name">';
		  	echo $product->Nome;
		  	echo '</span><span class="product-categories">';
		  	echo implode(', ', $product->Categoria);
		  	echo '</span></td>';
		  	echo '<td class="table-column column-photo"><img class="photo" src="';
						
			if($product->Fotos[0] != null){
				$file = "imagensBanco/photo".$product->Id."". $product->Fotos[0][1];
				if(file_exists($file)) @unlink($file);
					$fp = fopen($file, "a");
				$escreve = fwrite($fp, $product->Fotos[0][0]);
					
						// Fecha o arquivo
				fclose($fp);
			}
			else
				$file = "imagensBanco/imagemIndisponivel.bmp";
			echo $file;
						
			echo '"/></td>';
		  	echo '<td class="table-column amount">';
		  	echo $product->Quantidade; 
		  	echo'</td>';
		  	echo '<td class="table-column single-price">';
		  	echo $product->UltimoPreco;
		  	echo '</tde';
		  	
		  	echo '</tr>';
		  	
		  	$total = $total + ($product->Quantidade * $product->UltimoPreco);
		  }
		  
		  echo '</table>
		  <div id="total"><h3>Total</h3> <p><strong>';
		   echo "R$ ".$total; 
		   echo '</strong></p> </div>';
		  ?>
		  
		
	
</form>